<template>
  <div>
    <div>tom:{{ count }}}</div>
    <button @click="add">+1</button>
  </div>
</template>

<script>
import bus from '@/utils/eventBus'
export default {
  data() {
    return {
    //   count: 0
    }
  },
  computed: {
    count() {
      return this.$store.state.tomCount
    }
  },
  mounted() {
    bus.$on('add-tom', (data) => {
      this.count += data
    })
  },
  methods: {
    add() {
    //   bus.$emit('add-jerry', 1)
    // 可以直接修改公共数据，不推荐违反vuex单向数据流的规定
    // this.$store.state.jerryCount += 1
      this.$store.commit('addJerry', 1)
    }
  }
}
</script>

<style>

</style>
